package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModEducat;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dao.repository.PsCModEducatRepository;
import com.auxgroup.hr.front.service.modperson.ModEducatService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 教育经历流程信息service
 */
@Service("modEducatService")
public class ModEducatServiceImpl implements ModEducatService {
	private static final Logger logger = LoggerFactory.getLogger(ModEducatServiceImpl.class);
	
	@Autowired
	private PsCModEducatRepository PsCModEducatRepository;


	@Override
	public PsCModEducat getModEducat(PsCModPerPrimary modPerPrimary) {
		return PsCModEducatRepository.findOne(modPerPrimary);
	}


	@Override
	public PsCModEducat save(PsCModEducat ModEducat,UserDTO user) {
		ModEducat.setHrsRowAddOprid(user.getOprId());
		ModEducat.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModEducat.setHrsRowUpdOprid(user.getOprId());
		ModEducat.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModEducat,ignoreFields);
		return PsCModEducatRepository.save(ModEducat);
	}


	@Override
	public Boolean delete(PsCModPerPrimary modPerPrimary) {
		try {
			PsCModEducatRepository.delete(modPerPrimary);
		} catch (Exception e) {
			logger.error("delete ModEducat error: modPerPrimary={}",modPerPrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModEducat> getAll(String emplId) {
		PsCModEducat ModEducat = new PsCModEducat();
		ModEducat.setEmplid(emplId);
		return PsCModEducatRepository.findAll(Example.of(ModEducat));
	}


	@Override
	public List<PsCModEducat> getAllModEducat(String transNum, String emplid) {
		PsCModEducat ModEducat = new PsCModEducat();
		ModEducat.setEmplid(emplid);
		ModEducat.setcTransactionNbr(transNum);
		return PsCModEducatRepository.findAll(Example.of(ModEducat));
	}


	
	
	
}
